import 'dart:io';

import 'package:path_provider/path_provider.dart';

class FileTool{
  //获取本地存取路径的目录
  static Future<String> getStorageDir({required String relativePath}) async{
    Directory fileDr = await getTemporaryDirectory();
    String dirPath = fileDr.path+'/';
    dirPath += relativePath!=null?relativePath:"";
    await Directory(dirPath).create(recursive: true);
    return dirPath;
  }
  static Future<bool> isFileExist(path) async {
    String dirPath = await getStorageDir(relativePath: path);
    File file = File(dirPath+path);
    bool isExist = await file.exists();

    return isExist;
  }

  static String getFileName(String path) {
    var index1 = path.lastIndexOf("/");
    var index2 = path.length;
    var fileName = path.substring(index1 + 1, index2);
    return fileName;
  }

  // 截取文件后缀
  static String getSuffixName(String path) {
    var index1 = path.lastIndexOf(".");
    var index2 = path.length;
    var type = path.substring(index1,index2).toUpperCase();
    return type;
  }

}